using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;

namespace PKGames.AssetLoader
{
	public static class HtmlFileHelper
	{
		public static string LocalPath => Application.persistentDataPath + "/html5_games";

		public static bool IsDownloaded(string name)
		{
			string zipLocalPath = GetZipLocalPath(name);
			return Directory.Exists(zipLocalPath);
		}

		public static string GetZipLocalPath(string name)
		{
			if (!Directory.Exists(LocalPath))
			{
				Directory.CreateDirectory(LocalPath);
			}
			return LocalPath + "/" + name.Replace(" ", string.Empty) + ".zip";
		}

		public static long GetCRCFromFileName(string fileName)
		{
			try
			{
				string value = Regex.Match(fileName, "\\%5B([^)]*)\\%5D").Groups[1].Value;
				UnityEngine.Debug.LogError(value);
				return long.Parse(value);
			}
			catch (Exception ex)
			{
				UnityEngine.Debug.LogError(ex.ToString());
			}
			return 0L;
		}
	}
}
